var db = require('../../db/db');
var publictool = require("../../publictool/publictool");

exports.port = function (req, res) {
    var requestData = '';
    req.addListener('data', function (postDataChunk) {
        requestData += postDataChunk;
    });

    req.addListener('end', function () {
        publictool.putlog(req, requestData);
        var phone = publictool.checkoutdata(res, requestData);
        if (!phone) {
            return;
        }

        var client = db.client();
        db.checkuser(client, res, true, phone.accesstoken)
            .then(function (resultvalue) {
                var modSql = 'UPDATE device SET ischeck = ? WHERE manager = ?';
                var modSqlParams = [phone.check, resultvalue.account];
                client.query(modSql, modSqlParams, function (err, result) {
                    if (err) {
                        publictool.returnErr(res, '更新参数错误:' +'[UPDATE ERROR] - ' + err.message, 1);
                        client.end();
                        return;
                    }

                    publictool.returnErr(res, '操作成功', 0);
                    client.end();
                    return;
                });
            });
    });
};